package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserDevice;

import java.util.List;

/**
 * @Description: 用户设备表 Mapper 接口
 * @Author: DHC
 * @Date:  2020-12-01
 */
public interface SysUserDeviceMapper extends BaseMapper<SysUserDevice> {
//	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
//	List<String> getRoleByUserName(@Param("username") String username);
//
//	@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
//	List<String> getRoleIdByUserName(@Param("username") String username);

	@Select("select * from sys_user_device where work_no = #{workNo}")
	List<SysUserDevice> queryUserDevices(@Param("workNo") String workNo);

	@Select("select * from sys_user_device where work_no = #{workNo} and mobile_single = #{mobileSingle}")
	SysUserDevice queryUserDevice(@Param("workNo") String workNo, @Param("mobileSingle") String mobileSingle);

	@Delete("delete from sys_user_device where work_no in (${workNos})")
	void deleteUserDevice(@Param("workNos") String workNos);

	@Delete("delete from sys_user_device where work_no = #{workNo} and mobile_single = #{mobileSingle}")
	int deleteUserDeviceByWorkNoAndMobileSingle(@Param("workNo") String workNo, @Param("mobileSingle") String mobileSingle);

	@Select("select * from sys_user_device where work_no in (select work_no from sys_user where app_push = '1')")
	List<SysUserDevice> getSysUserDeviceByAppPush();

	@Delete("delete from sys_user_device where work_no = #{workNo} and phone = #{phone}")
	void deleteSysUserDevice(@Param("workNo") String workNo, @Param("phone") String phone);

	@Select("select count(*) ct from sys_user_device where event_type = 1") // 1 进场 2出厂
	int getDeviceInCount();

	@Select("select count(*) ct from sys_user_device")
	int getDeviceCount();

	@Select("select count(*) ct from sys_user_device where client_type = 'Android'")
	int getDeviceAndroidCount();

	@Select("select count(*) ct from sys_user_device where client_type = 'iOS'")
	int getDeviceIosCount();

}
